//
//  DYMyShopDetailVC.m
//  TerritoryShopkeeper
//
//  Created by 黄德玉 on 2018/6/22.
//  Copyright © 2018年 ZDQK. All rights reserved.
//

#import "DYMyShopDetailVC.h"
#import <Masonry/Masonry.h>
#import "DYShopModel.h"

@interface DYMyShopDetailVC ()
@property (nonatomic,strong) UIScrollView * scrollView;
@property (nonatomic,strong) UIView * scrollContentView;
@property (nonatomic,strong) UIImageView * logo;
@property (nonatomic,strong) UILabel * titleLabel;
@property (nonatomic,strong) UIImageView * vipView;
@property (nonatomic,strong) UILabel * shopTitle;
@property (nonatomic,strong) UILabel * shopName;
@property (nonatomic,strong) UILabel * zhizhaoLabel;
@property (nonatomic,strong) UILabel * renzhengLabel;
@property (nonatomic,strong) UILabel * shimingTitle;
@property (nonatomic,strong) UILabel * shimingContent;

@end

@implementation DYMyShopDetailVC

- (void)loadView{
    self.view = self.scrollView;
}

- (void)_addViews{
    self.logo = [[UIImageView alloc] init];
//    self.logo.backgroundColor = [UIColor orangeColor];
    [self.scrollContentView addSubview:self.logo];
    
    self.titleLabel = [UILabel new];
    self.titleLabel.text = @"澳大利亚红酒专卖店";
    self.titleLabel.textColor = [UIColor darkTextColor];
    self.titleLabel.font = [UIFont systemFontOfSize:18];
    [self.scrollContentView addSubview:self.titleLabel];
    
    self.vipView = [UIImageView new];
    self.vipView.image = [UIImage imageNamed:@"VIP"];
    [self.scrollContentView addSubview:self.vipView];
    
    self.shopTitle = [UILabel new];
    self.shopTitle.text = @"店铺名称";
    self.shopTitle.textColor = [UIColor colorWithHex:0x949494 alpha:1];
    [self.scrollContentView addSubview:self.shopTitle];
    self.shopTitle.font = [UIFont systemFontOfSize:14];
    
    self.shopName = [UILabel new];
    self.shopName.textColor = [UIColor darkTextColor];
    self.shopName.text = @"澳大利亚";
    [self.scrollContentView addSubview:self.shopName];
    self.shopName.textAlignment = NSTextAlignmentRight;
    self.shopName.font = [UIFont systemFontOfSize:14];
    
    self.zhizhaoLabel = [UILabel new];
    self.zhizhaoLabel.textColor = [UIColor colorWithHex:0x949494 alpha:1];
    self.zhizhaoLabel.text = @"工商营业执照";
    [self.scrollContentView addSubview:self.zhizhaoLabel];
    self.zhizhaoLabel.font = [UIFont systemFontOfSize:14];
    
    self.renzhengLabel = [UILabel new];
    self.renzhengLabel.textColor = [UIColor colorWithHex:0x2cbf38 alpha:1];
    self.renzhengLabel.text = @"已认证";
    [self.scrollContentView addSubview:self.renzhengLabel];
    self.renzhengLabel.textAlignment = NSTextAlignmentRight;
    self.renzhengLabel.font = [UIFont systemFontOfSize:14];
    
    self.shimingTitle = [UILabel new];
    self.shimingTitle.textColor =  [UIColor colorWithHex:0x949494 alpha:1];
    self.shimingTitle.text = @"实名";
    [self.scrollContentView addSubview:self.shimingTitle];
    self.shimingTitle.font = [UIFont systemFontOfSize:14];
    
    self.shimingContent = [UILabel new];
    self.shimingContent.textColor = [UIColor colorWithHex:0x2cbf38 alpha:1];
    self.shimingContent.text = @"已认证";
    self.shimingContent.textAlignment = NSTextAlignmentRight;
    [self.scrollContentView addSubview:self.shimingContent];
    self.shimingContent.font = [UIFont systemFontOfSize:14];

    [self _layout];
    
}

- (void)_layout{
    [self.logo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.scrollContentView).offset(10);
        make.top.equalTo(self.scrollContentView).offset(24);
        make.width.equalTo(@113);
        make.height.equalTo(@39);
       
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.logo.mas_right).offset(10);
        make.top.equalTo(self.logo);
        make.right.equalTo(self.scrollContentView);
    }];
    [self.vipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.logo.mas_right).offset(10);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(7.5);
    }];
    UIView * blank_1  = [UIView new];
    blank_1.backgroundColor = [UIColor colorWithHex:0xeef1f3 alpha:1];
    [self.scrollContentView addSubview:blank_1];
    [blank_1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.scrollContentView);
        make.height.equalTo(@10);
        make.top.equalTo(self.logo.mas_bottom).offset(25);
    }];

    [self.shopTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.scrollContentView).offset(10);
        make.top.equalTo(blank_1.mas_bottom).offset(15);
    }];
    [self.shopName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.scrollContentView).offset(-10);
        make.centerY.equalTo(self.shopTitle);
        make.width.equalTo(@200);
    }];

    UIView * blank_2 = [UIView new];
    blank_2.backgroundColor = [UIColor colorWithHex:0xeef1f3 alpha:1];
    [self.scrollContentView addSubview:blank_2];
    [blank_2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.scrollContentView);
        make.top.equalTo(self.shopTitle.mas_bottom).offset(15);
        make.height.equalTo(@10);
    }];

    [self.zhizhaoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.scrollContentView).offset(10);
        make.top.equalTo(blank_2.mas_bottom).offset(15);
    }];

    [self.renzhengLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.scrollContentView).offset(-10);
        make.centerY.equalTo(self.zhizhaoLabel);
        make.width.equalTo(@200);
    }];

    UIView * blank_3 = [UIView new];
    blank_3.backgroundColor = [UIColor colorWithHex:0xeef1f3 alpha:1];
    [self.scrollContentView addSubview:blank_3];

    [blank_3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.scrollContentView);
        make.top.equalTo(self.zhizhaoLabel.mas_bottom).offset(15);
        make.height.equalTo(@10);
    }];

    [self.shimingTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.scrollContentView).offset(10);
        make.top.equalTo(blank_3.mas_bottom).offset(15);
    }];
    [self.shimingContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.scrollContentView).offset(-10);
        make.centerY.equalTo(self.shimingTitle);
        make.width.equalTo(@200);
    }];
    UIView * blank_4 = [UIView new];
    blank_4.backgroundColor = [UIColor colorWithHex:0xeef1f3 alpha:1];
    [self.scrollContentView addSubview:blank_4];
    [blank_4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.scrollContentView);
        make.top.equalTo(self.shimingTitle.mas_bottom).offset(15);
        make.height.equalTo(@10);
        make.bottom.equalTo(self.scrollContentView);
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self _addViews];
    [self _loadData];
}

- (void)_loadData{
    [MBProgressHUD showHUDProgress:self.view animated:YES];
    __weak typeof(self) weakSelf = self;
    [MYAFNetworking POST:@"api2/getShopDetails" parameters:@{@"sid":self.sid} success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
        NSString * code = [responseObject safeStringForKey:@"code"];
        if ([code isEqualToString:@"200"]) {
            DYShopModel * model = [DYShopModel mj_objectWithKeyValues:[responseObject safeObjectForKey:@"data"]];
            weakSelf.titleLabel.text = model.sname;
            if (!model.isvip) {
                weakSelf.vipView.hidden = YES;
            }
            weakSelf.shopName.text = model.sname;
            [weakSelf.logo sd_setImageWithURL:[NSURL URLWithString:model.simg]];
            return;
        }
        [MBProgressHUD showError:weakSelf.view title:[responseObject safeStringForKey:@"message"] code:code animated:YES];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
    }];
}

- (UIScrollView *)scrollView{
    if (!_scrollView) {
        _scrollView = [UIScrollView new];
        _scrollContentView = [UIView new];
        [_scrollView addSubview:_scrollContentView];
        _scrollContentView.backgroundColor = [UIColor whiteColor];
        [_scrollContentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(_scrollView);
            make.width.equalTo(_scrollView);
        }];
    }
    return _scrollView;
}

@end
